package com.alquimia.truco.dominio.modelo;

import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Stream;

/**
 * Created by Ivo on 28/06/2014.
 */
public class Mazo {

    private Queue<Carta> cartas;
    private final SecureRandom sRandom = new SecureRandom();

    protected Mazo() {
        super();
        barajar();
    }

    public void barajar() {
        List<Carta> cartasSinBarajar = Arrays.asList(Carta.values());
        Collections.shuffle(cartasSinBarajar, sRandom);
        setCartas(new LinkedBlockingQueue<Carta>(cartasSinBarajar));
    }

    public Carta obtenerCarta() {
        return cartas.poll();
    }

    public List<Carta> obtenerCartas(int aCantidad) {
        List<Carta> mCartas = new ArrayList(aCantidad);
        for (int i = 0; i < aCantidad; i++)
            mCartas.add(cartas.poll());
        return mCartas;
    }

    private void setCartas(Queue<Carta> aCartas) {
        this.cartas = aCartas;
    }


}
